﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Space
{
    class FighterShip : NewtonShip
    {
        public Ship Host { get; set; }
        public override float Angle
        {
            get
            {
                return (float)Math.Atan2(Host.Position.Z - Position.Z, Host.Position.X - Position.X);
            }
        }

        public FighterShip(Game game)
            : base(game)
        {
            
        }
        public override void Update(float time)
        {
            if (Alive)
            {
                pushCooldown -= time;
                if (pushCooldown <= 0)
                {
                    Vector3 dest = Host.Position;
                    float distanceSquare = (dest - Position).LengthSquared();
                    //if (distanceSquare > Fleet.Size * 4 / 6)
                    {
                        if (distanceSquare > Speed * Speed)
                        {
                            Vector3 dir = dest - Position;
                            dir.Normalize();
                            Position += dir * Speed;
                        }
                    }
                }
            }
            fire += time;
            if (fire >= FireInterval && Target != null)
            {
                Fire();
                fire = 0;
            }
        }
    }
}
